import 'package:bili_caricature/pages/cubit/information_detail/information_detail_cubit.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../pages/bloc/novel_detail/novel_detail_bloc.dart';
import '../pages/bloc/novel_detail/novel_detail_nav_bloc.dart';
import '../pages/bloc/novel_detail/novel_detail_page.dart';
import '../pages/cubit/information_detail/information_detail_page.dart';
import '../pages/mine/bili_mine/cubit.dart';
import '../pages/mine/bili_mine/view.dart';
import '../pages/tabar/view.dart';
import 'irouter_provider.dart';

class HomeRouter extends IRouterProvider {
  static const messageDetailPage = "/pages/home/message_module/InformationDetailPage"; //资讯详情
  static const novelDetailPage = "/pages/home/novel_detail/NovelDetailPage"; //小说详情
  static const biliMinePage = "/pages/home/novel_detail/BiliMinePage"; //小说详情
  static const biliTabarPage = "/pages/home/tabbar/BiliTabarPage"; //小说详情

  @override
  void initRouter(FluroRouter router) {
    /// 主控制器
    router.define(biliTabarPage, handler: Handler(handlerFunc: (context, params) {
      return const BiliTabarPage();
    }));

    /// 资讯详情
    router.define(messageDetailPage, handler: Handler(handlerFunc: (context, params) {
      Map? argument = context!.settings!.arguments as Map?;
      int entityId = argument?['entityId'];
      return BlocProvider<InformationDetailCubit>(
        create: (BuildContext context) => InformationDetailCubit(),
        child: InformationDetailPage(
          entityId: entityId,
        ),
      );
    }));

    ///小说详情
    router.define(novelDetailPage, handler: Handler(handlerFunc: (context, params) {
      Map? argument = context!.settings!.arguments as Map?;
      String imageUrl = argument?['imageUrl'];
      return BlocProvider<NovelDetailBloc>(
        create: (BuildContext context) => NovelDetailBloc(),
        child: BlocProvider<NovelDetailNavBloc>(
          create: (BuildContext context) => NovelDetailNavBloc(),
          child: NovelDetailPage(
            imageUrl: imageUrl,
          ),
        ),
      );
    }));

    /// 资讯详情
    router.define(biliMinePage, handler: Handler(handlerFunc: (context, params) {
      Map? argument = context!.settings!.arguments as Map?;
      String imageUrl = argument?['imageUrl'];
      return BlocProvider<BiliMineCubit>(
        create: (BuildContext context) => BiliMineCubit(),
        child: BiliMinePage(
          imageUrl: imageUrl,
        ),
      );
    }));
  }
}
